package org.paradise.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.EquippmDao;
import org.paradise.pojo.Equippm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/EquipPm")
public class EquipPmController {

    @Autowired
    private EquippmDao equippmDao;

    //查询所有商品数据调用的方法
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,Integer id) throws Exception{
        Map<String,Object> map = new HashMap<>();
        Page<Equippm> pager = PageHelper.startPage(page,limit);
        List<Equippm> list = equippmDao.getidAll(id);
        map.put("count",pager.getTotal());  //条数
        map.put("data",list);   //数据
        map.put("code",0);   //状态
        map.put("msg","");   //返回的日志
        return map;
    }
    //添加参数
    @PostMapping("/addcs")
    @ResponseBody
    public Map<String,Object> addsp(Equippm equippm) throws Exception{
        Map<String,Object> map=new HashMap<>();
        equippmDao.add(equippm);
        map.put("result",true);
        return map;
    }
    //批量删调用的方法
    @RequestMapping(value = "/batchDelete",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> batchDelete(Integer[] id) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        equippmDao.batchDelete(id);
        map.put("result",true);
        return map;
    }

    //修改绑定值
    @RequestMapping("/idcs")
    @ResponseBody
    public Equippm idshopping(Integer id)throws Exception{
        return equippmDao.get(id);
    }

    //修改设备参数
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(Equippm equippm) throws Exception{
        Map<String,Object> map = new HashMap<>();
        equippmDao.update(equippm);
        map.put("result",true);
        return map;
    }
}